package main

import (
	"fmt"
	"strconv"
	"time"
)

type Person struct {
	name string
}

func (p Person) show() {
	fmt.Println("Person--->", p.name)
}

type People = Person

type Student struct {
	//嵌入两个结构体
	Person
	People
}

func main() {
	/**
	type:用于定义类型和类型别名
	1、类型定义：type 类型名 Type
	2、类型别名：type 类型名 = Type
	*/
	var i1 myint
	var i2 = 100
	i1 = 200
	fmt.Println(i1, i2)

	var name mystr
	name = "王二狗"
	var s1 = "李小花啊"
	fmt.Println(name, s1)

	//i1 = i2  -- cannot use i2 (type int) as type myint in assignment
	//name = s1  -- cannot use s1 (type string) as type mystr in assignment
	fmt.Printf("%T,%T,%T,%T \n", i1, i2, name, s1)

	fmt.Println("------------------")
	res1 := fun1()
	fmt.Println(res1(10, 20))
	fmt.Println("------------------")

	var i3 myint2
	i3 = 1000
	fmt.Println(i3)

	i3 = i2
	fmt.Println(i3)

	fmt.Printf("%T,%T,%T  \n", i1, i2, i3)

	var s Student
	s.Person.name = "王二狗"
	s.Person.show()
	fmt.Printf("%T,%T \n", s.Person, s.People)

}

//1、定义一个新的类型
type myint int
type mystr string

//2、定义函数类型
type myfunc func(int, int) string

func fun1() myfunc {
	fun := func(a, b int) string {
		s := strconv.Itoa(a) + strconv.Itoa(b)
		return s
	}
	return fun
}

//3、定义类型别名
type myint2 = int //不是重新定义新的类型，只是给int起别名，和int可以通用

type MyDuration time.Duration

func (m MyDuration) SimpleSelect() {

}
